package com.cloud.wms.widget.dialog;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.cloud.core.widget.dialog.CommonDialog;
import com.cloud.wms.R;

import java.text.MessageFormat;

/**
 * @Author:Chen
 * @Date: 2021-03-29 14:39
 * @Description:
 */
public class ConfirmAmountDialog extends CommonDialog {

    private final Context context;
    private TextView tvTitle, tvAmount;
    private Button btnConfirm;
    private ImageView btnCancel;
    private OnConfirmListener onConfirmListener;
    private int amount;

    public ConfirmAmountDialog(@NonNull Context context, int amount) {
        super(context);
        this.context = context;
        this.amount = amount;
    }

    @Override
    protected int resId() {
        return R.layout.dialog_confirm_amount;
    }

    @Override
    protected void initEvent() {
        tvTitle = findViewById(R.id.tv_title);
        btnCancel = findViewById(R.id.btn_cancel);
        tvAmount = findViewById(R.id.tv_amount);
        btnConfirm = findViewById(R.id.btn_confirm);

        tvAmount.setText(MessageFormat.format("{0}", amount));

        btnCancel.setOnClickListener(view -> dismiss());

        btnConfirm.setOnClickListener(v -> {
            if (onConfirmListener != null) {
                onConfirmListener.onConfirm(amount);
            }
            dismiss();
        });
    }

    public void setOnConfirmListener(OnConfirmListener onConfirmListener) {
        this.onConfirmListener = onConfirmListener;
    }

    public interface OnConfirmListener {
        void onConfirm(int amount);
    }
}
